<template>
  <div class="login-container">
    <!-- 顶部蓝底白字导航栏 -->
    <div class="header">
      <span class="logo-text">云进销存</span>
    </div>

    <!-- 登录表单 -->
    <div class="form-container">
      <div class="user-icon">
        <el-icon :size="60"><User /></el-icon>
      </div>
      <h2>用户登录</h2>
      
      <el-form ref="loginForm" :model="form" :rules="rules">
        <el-form-item prop="username">
          <el-input
            v-model="form.username"
            placeholder="用户名"
            prefix-icon="el-icon-user"
          ></el-input>
        </el-form-item>
        
        <el-form-item prop="password">
          <el-input
            v-model="form.password"
            type="password"
            placeholder="密码"
            prefix-icon="el-icon-lock"
            show-password
          ></el-input>
        </el-form-item>
        
        <el-form-item prop="company">
          <el-input
            v-model="form.company"
            placeholder="公司"
            prefix-icon="el-icon-office-building"
          ></el-input>
        </el-form-item>
        
        <el-form-item>
          <el-button 
            type="primary" 
            @click="submitForm" 
            class="login-btn"
          >
            登录
          </el-button>
          <el-button 
            type="primary" 
            @click="retu"
            class="login-btn"
          >
            返回跳转首页
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { User } from '@element-plus/icons-vue'

export default {
  name: 'LoginPage',
  components: { User },
  data() {
    return {
      form: {
        username: '',
        password: '',
        company: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
        company: [
          { required: true, message: '请输入公司名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    //返回跳转首页
    retu(){
      this.$router.push({
        name: 'Home', 
      });
    },
    submitForm() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          // 这里调用登录API
          this.$message.success('登录成功')
          // 跳转到首页
          this.$router.push({name: 'Home'});
        }
      })
    }
  }
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  background-color: #f5f7fa;
}

.header {
  background-color:#1f2d3d;
  color: white;
  height: 60px;
  line-height: 60px;
  text-align: center;
  font-size: 20px;
  font-weight: bold;
}

.form-container {
  width: 400px;
  margin: 50px auto;
  padding: 40px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  text-align: center;
}

.user-icon {
  margin-bottom: 20px;
  color: #409EFF;
}

h2 {
  margin-bottom: 30px;
  color: #303133;
  font-size: 18px;
  font-weight: normal;
}

.login-btn {
  width: 100%;
  background-color: #409EFF;
  border-color: #409EFF;
  height: 40px;
  font-size: 16px;
  margin-top: 10px;
  margin-left: 0px;
}

/* 调整输入框样式 */
:deep(.el-input__inner) {
  height: 40px;
  background-color: #f5f7fa;
  border-color: #e4e7ed;
}

:deep(.el-input__prefix) {
  display: flex;
  align-items: center;
  padding-left: 10px;
}

:deep(.el-icon) {
  font-size: 16px;
  color: #c0c4cc;
}
</style>